package com.weex.app;

import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.taobao.weex.appfram.navigator.IActivityNavBarSetter;
import com.taobao.weex.common.Constants;
import com.taobao.weex.utils.WXLogUtils;
import com.weex.app.extend.ImageAdapter;
import com.weex.app.extend.WXNavigatorModule;
import com.alibaba.weex.plugin.loader.WeexPluginContainer;
import com.weex.app.util.AppConfig;
import com.taobao.weex.InitConfig;
import com.taobao.weex.WXSDKEngine;
import com.taobao.weex.common.WXException;
import com.taobao.weex.WXEnvironment;

public class WXApplication extends Application {

    /**
     * @param connectable debug server is connectable or not.
     *                    if true, sdk will try to connect remote debug server when init WXBridge.
     * @param debuggable  enable remote debugger. valid only if host not to be "DEBUG_SERVER_HOST".
     *                    true, you can launch a remote debugger and inspector both.
     *                    false, you can  just launch a inspector.
     * @param host        the debug server host, must not be "DEBUG_SERVER_HOST", a ip address or domain will be OK.
     *                    for example "127.0.0.1".
     */
    private void initDebugEnvironment(boolean connectable, boolean debuggable, String host) {
        WXEnvironment.sApplication = this;
//        WXEnvironment.sRemoteDebugMode = true;

        WXEnvironment.sDebugServerConnectable = true;
        WXEnvironment.sRemoteDebugProxyUrl = "ws://121.42.239.28:8088/debugProxy/native/1";
//        WXEnvironment.sDebugNetworkEventReporterEnable = true;
//        WXEnvironment.sDynamicMode = true;
//        WXEnvironment.sDynamicUrl = "ws://192.168.3.117:8088/debugProxy/native/";


    }

    @Override
    public void onCreate() {
        super.onCreate();
//        com.taobao.weex.devtools.WeexInspector.overrideWebSocketClient(new CustomWebSocketClient());

        initDebugEnvironment(false, true, "192.168.3.117");

        final Context ctx = this.getApplicationContext();
        WXSDKEngine.addCustomOptions("appName", "WXSample");
        WXSDKEngine.addCustomOptions("appGroup", "WXApp");
        WXSDKEngine.initialize(this,
                new InitConfig.Builder().setImgAdapter(new ImageAdapter()).build()
        );
        try {
            WXSDKEngine.registerModule("navigator", WXNavigatorModule.class);
        } catch (WXException e) {
            e.printStackTrace();
        }
        AppConfig.init(this);
//        WeexPluginContainer.loadAll(this);


    }


}
